//
//  GRTools.m
//  BaseProject
//
//  Created by karong on 2023/7/24.
//

#import "GRTools.h"
#import "sys/utsname.h"

@implementation GRTools

+ (NSString *)fullWebUrl:(NSString *)url {
    NSMutableString *webUrl = [[NSMutableString alloc]initWithString:url];
    [webUrl appendFormat:@"?lang_type=%d",3];
    [webUrl appendFormat:@"&version_code=%@",[[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"]];
    [webUrl appendFormat:@"&name=%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]];
    [webUrl appendFormat:@"&os_type=%@",@"ios"];
    [webUrl appendFormat:@"&channel=%@",@"AppStore"];
    [webUrl appendFormat:@"&user_id=%ld",(long)appUserCenter.id];
    if (!GRIsNullOrEmpty(appUserCenter.token)) {
        [webUrl appendFormat:@"&token=%@",appUserCenter.token];
    }
    return webUrl;
}

///过滤换行
+ (NSString *)newContent:(NSString *)content {
    content = [content stringByReplacingOccurrencesOfString:@"\n\r" withString:@"\n"];
    content = [content stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"];
    content = [content stringByReplacingOccurrencesOfString:@"\n\n" withString:@"\n"];
    content = [content stringByReplacingOccurrencesOfString:@"\t\n" withString:@"\n"];
    content = [content stringByReplacingOccurrencesOfString:@"\t\t" withString:@"\n"];
    content = [content stringByReplacingOccurrencesOfString:@"\r\r" withString:@"\n"];
    content = [content stringByReplacingOccurrencesOfString:@"\n\t" withString:@"\n"];
    content = [self removeMorenNewline:content];
    return content;
}

///过滤标签
+ (NSString *)removeMorenNewline:(NSString *)content{
    if (content.length == 0) {
        return @"";
    }
    NSArray *datas = [content componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self <> ''"];
    datas = [datas filteredArrayUsingPredicate:predicate];
    NSMutableArray *listData = @[].mutableCopy;
    [datas enumerateObjectsUsingBlock:^(NSString *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString *str = [obj stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
        if (str.length > 0) {
            [listData addObject:str];
        }
    }];
    content = [listData componentsJoinedByString:@"\n"];
    return content;
}

+ (NSString *)phoneModel {
  // 需要#import "sys/utsname.h"
     struct utsname systemInfo;
     uname(&systemInfo);
     NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
     //iPhone
     if ([deviceString isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
     if ([deviceString isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
     if ([deviceString isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
     if ([deviceString isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
     if ([deviceString isEqualToString:@"iPhone3,2"])    return @"Verizon iPhone 4";
     if ([deviceString isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
     if ([deviceString isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
     if ([deviceString isEqualToString:@"iPhone5,2"])    return @"iPhone 5";
     if ([deviceString isEqualToString:@"iPhone5,3"])    return @"iPhone 5C";
     if ([deviceString isEqualToString:@"iPhone5,4"])    return @"iPhone 5C";
     if ([deviceString isEqualToString:@"iPhone6,1"])    return @"iPhone 5S";
     if ([deviceString isEqualToString:@"iPhone6,2"])    return @"iPhone 5S";
     if ([deviceString isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
     if ([deviceString isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
     if ([deviceString isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
     if ([deviceString isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
     if ([deviceString isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
     if ([deviceString isEqualToString:@"iPhone9,1"])    return @"iPhone 7";
     if ([deviceString isEqualToString:@"iPhone9,3"])    return @"iPhone 7";
     if ([deviceString isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus";
     if ([deviceString isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus";
     if ([deviceString isEqualToString:@"iPhone10,1"])    return @"iPhone 8";
     if ([deviceString isEqualToString:@"iPhone10,4"])    return @"iPhone 8";
     if ([deviceString isEqualToString:@"iPhone10,2"])    return @"iPhone 8 Plus";
     if ([deviceString isEqualToString:@"iPhone10,5"])    return @"iPhone 8 Plus";
     if ([deviceString isEqualToString:@"iPhone10,3"])    return @"iPhone X";
     if ([deviceString isEqualToString:@"iPhone10,6"])    return @"iPhone X";
     if ([deviceString isEqualToString:@"iPhone11,8"])    return @"iPhone XR";
     if ([deviceString isEqualToString:@"iPhone11,2"])    return @"iPhone XS";
     if ([deviceString isEqualToString:@"iPhone11,6"])    return @"iPhone XS Max";
     if ([deviceString isEqualToString:@"iPhone12,1"])    return @"iPhone 11";
     if ([deviceString isEqualToString:@"iPhone12,3"])    return @"iPhone 11 Pro";
     if ([deviceString isEqualToString:@"iPhone12,5"])    return @"iPhone 11 ProMax";
     if ([deviceString isEqualToString:@"iPhone13,1"])    return @"iPhone 12";
     if ([deviceString isEqualToString:@"iPhone13,3"])    return @"iPhone 12 Pro";
    if ([deviceString isEqualToString:@"iPhone13,4"])    return @"iPhone 12 Pro Max";
    if ([deviceString isEqualToString:@"iPhone14,4"])    return @"iPhone 13 mini";
    if ([deviceString isEqualToString:@"iPhone14,5"])    return @"iPhone 13";
    if ([deviceString isEqualToString:@"iPhone14,2"])    return @"iPhone 13 Pro";
    if ([deviceString isEqualToString:@"iPhone14,3"])    return @"iPhone 13 Pro Max";
    if ([deviceString isEqualToString:@"iPhone14,6"])    return @"iPhone SE";
    if ([deviceString isEqualToString:@"iPhone14,7"])    return @"iPhone 14";
    if ([deviceString isEqualToString:@"iPhone14,8"])    return @"iPhone 14 Plus";
    if ([deviceString isEqualToString:@"iPhone15,2"])    return @"iPhone 14 Pro";
    if ([deviceString isEqualToString:@"iPhone15,3"])    return @"iPhone 14 Pro Max";


     //iPod
     if ([deviceString isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";
     if ([deviceString isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
     if ([deviceString isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
     if ([deviceString isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
     if ([deviceString isEqualToString:@"iPod5,1"])      return @"iPod Touch 5G";
     
     //iPad
     if ([deviceString isEqualToString:@"iPad1,1"])      return @"iPad";
     if ([deviceString isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
     if ([deviceString isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
     if ([deviceString isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
     if ([deviceString isEqualToString:@"iPad2,4"])      return @"iPad 2 (32nm)";
     if ([deviceString isEqualToString:@"iPad2,5"])      return @"iPad mini (WiFi)";
     if ([deviceString isEqualToString:@"iPad2,6"])      return @"iPad mini (GSM)";
     if ([deviceString isEqualToString:@"iPad2,7"])      return @"iPad mini (CDMA)";
     
     if ([deviceString isEqualToString:@"iPad3,1"])      return @"iPad 3(WiFi)";
     if ([deviceString isEqualToString:@"iPad3,2"])      return @"iPad 3(CDMA)";
     if ([deviceString isEqualToString:@"iPad3,3"])      return @"iPad 3(4G)";
     if ([deviceString isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
     if ([deviceString isEqualToString:@"iPad3,5"])      return @"iPad 4 (4G)";
     if ([deviceString isEqualToString:@"iPad3,6"])      return @"iPad 4 (CDMA)";
     
     if ([deviceString isEqualToString:@"iPad4,1"])      return @"iPad Air";
     if ([deviceString isEqualToString:@"iPad4,2"])      return @"iPad Air";
     if ([deviceString isEqualToString:@"iPad4,3"])      return @"iPad Air";
     if ([deviceString isEqualToString:@"iPad5,3"])      return @"iPad Air 2";
     if ([deviceString isEqualToString:@"iPad5,4"])      return @"iPad Air 2";
     if ([deviceString isEqualToString:@"i386"])         return @"Simulator";
     if ([deviceString isEqualToString:@"x86_64"])       return @"Simulator";
     
     if ([deviceString isEqualToString:@"iPad4,4"]
         ||[deviceString isEqualToString:@"iPad4,5"]
         ||[deviceString isEqualToString:@"iPad4,6"])      return @"iPad mini 2";
     
     if ([deviceString isEqualToString:@"iPad4,7"]
         ||[deviceString isEqualToString:@"iPad4,8"]
         ||[deviceString isEqualToString:@"iPad4,9"])      return @"iPad mini 3";
     
     return deviceString;

}
@end
